if(!window.addEventListener){
	window.addEventListener = window.attachEvent;
}
if(!document.addEventListener){
	document.addEventListener = document.attachEvent;
}

//以下为公共调用区域，用不上的，请删除(顺便删除最底下效果功能块)
$(function(){

		//算高度-全页
		$(".H_main").css("height",$(window).height()); 
		
		//算高度-有顶部
		$(".H_top").css("height",$(window).height()-70); 
		$(".circle-panel").css("height",$(window).height()-70); 
		
		//算高度-有顶部-有底部
		$(".H_top_bot").css("height",$(window).height()-145);

		//算高度-添加附加险-有底部
		$(".H_banner_bot").css("height",$(window).height()-145-$(".addBanner").height());
		$(".H_banner_bot").css("overflow","auto");

		//算高度-有顶部-有底部-有进度条
		$(".H_step").css("height",$(window).height()-212);

		//算高度-有顶部-tab
		$(".H_tab").css("height",$(window).height()-127);
		 
		//算高度-我的有顶部-tab
		$(".H_contentTop").css("height",$(window).height()-70-$(".contentTop").height());
		
		//复选调用
		$(".check_blo").chkAll();
		//单选调用
		$(".radio_blo").radioAll();
		//单选是否调用
		$(".radio_judge").radioJudge();
		// 单选性别调用
		$(".radio-sex").radioSex();
		//产品热卖左右滑动
//		$(".featured").swiperProduct();
		// 健康告知是否显示
		$(".radio_judge").collapseRadio();
		//健康告知全部否
		$(".judgeAllno").radioJudgeAllNo();
		//健康告知列表树
		$(".checkTree").checkMenu();
		//书架操作按钮弹出框
		$(".bookshelf").popover();
		$(".bookshelf-list").popover();
		//书架批量删除
		$(".removeBookshelf").removeBookshelf();
		//百年沧桑
		$(".swiper-nav").aboutHistory();
		//日期
		var opt = {
	        preset: 'date', //日期
	        theme: 'android-ics light', //皮肤样式
	        display: 'bottom', //显示方式 
	        mode: 'scroller', //日期选择模式
	        lang: 'zh',
	        dateFormat: 'yy-mm-dd', // 日期格式
	        setText: '确定', //确认按钮名称
	        cancelText: '取消',//取消按钮名籍我
	        dateOrder: 'yymmdd', //面板中日期排列格式
	        dayText: '', monthText: '', yearText: '', //面板中年月日文字
	        endYear:2020 //结束年份
    	};
		if($('input[data-role=datebox]').mobiscroll)
			$('input[data-role=datebox]').mobiscroll(opt);
		$(".toggle-click").click(function(){
			$(this).next().toggle();
			$(this).find(".toggle-panel").toggle();
			myScroll.refresh();
		})
});
//tab
function nTabs(thisObj,Num){
	if(thisObj.className == "active")return;
	var tabObj = thisObj.parentNode.id;
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");
	for(i=0; i <tabList.length; i++){
  		if (i == Num){
   			thisObj.className = "active";
      		document.getElementById(tabObj+"_Content"+i).style.display = "block";
  		}else{
   			tabList[i].className = "";
   			document.getElementById(tabObj+"_Content"+i).style.display = "none";
  		}
	}
}
//alert
function alertMsg(msg, mode, okCallback, callParam,cancelCallBack) { //mode为空，即只有一个确认按钮，mode为1时有确认和取消两个按钮
    msg = msg || '';
    mode = mode || 0;
    var top = document.body.scrollTop || document.documentElement.scrollTop;
    var isIe = (document.all) ? true : false;
    var isIE6 = isIe && !window.XMLHttpRequest;
    var sTop = document.documentElement.scrollTop || document.body.scrollTop;
    var sLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
    var winSize = function(){
        var xScroll, yScroll, windowWidth, windowHeight, pageWidth, pageHeight;
        // innerHeight获取的是可视窗口的高度，IE不支持此属性
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }

        if (self.innerHeight) {    // all except Explorer
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }

        // for small pages with total width less then width of the viewport
        if (xScroll < windowWidth) {
            pageWidth = windowWidth;
        } else {
            pageWidth = xScroll;
        }

        return{
            'pageWidth':pageWidth,
            'pageHeight':pageHeight,
            'windowWidth':windowWidth,
            'windowHeight':windowHeight
        }
    }();
    //alert(winSize.pageWidth);
    //遮罩层
    var styleStr = 'top:0;left:0;position:absolute;z-index:10000;background:#666;width:' + winSize.pageWidth + 'px;height:' +  (winSize.pageHeight + 30) + 'px;';
    styleStr += (isIe) ? "filter:alpha(opacity=80);" : "opacity:0.8;"; //遮罩层DIV
    var shadowDiv = document.createElement('div'); //添加阴影DIV
    shadowDiv.style.cssText = styleStr; //添加样式
    shadowDiv.id = "shadowDiv";
    //如果是IE6则创建IFRAME遮罩SELECT
    if (isIE6) {
        var maskIframe = document.createElement('iframe');
        maskIframe.style.cssText = 'width:' + winSize.pageWidth + 'px;height:' + (winSize.pageHeight + 30) + 'px;position:absolute;visibility:inherit;z-index:-1;filter:alpha(opacity=0);';
        maskIframe.frameborder = 0;
        maskIframe.src = "about:blank";
        shadowDiv.appendChild(maskIframe);
    }
    document.body.insertBefore(shadowDiv, document.body.firstChild); //遮罩层加入文档
    //弹出框
    var styleStr1 = 'display:block;position:fixed;_position:absolute;left:' + 20 + '%;top:' + 20 + '%;_top:' + (winSize.windowHeight / 2 + top - 150)+ 'px;'; //弹出框的位置
    var alertBox = document.createElement('div');
    alertBox.id = 'alertMsg';
    alertBox.style.cssText = styleStr1;
    //创建弹出框里面的内容P标签
    var alertMsg_info = document.createElement('P');
    alertMsg_info.id = 'alertMsg_info';
    alertMsg_info.innerHTML = msg;
    alertMsg_info.style.cssText = 'max-height: 400px;overflow: auto;';
    alertBox.appendChild(alertMsg_info);
    if(mode !== 1){
    	//创建按钮
        var btn1 = document.createElement('a');
        btn1.id = 'alertMsg_btn3';
        btn1.href = 'javas' + 'cript:void(0)';
        btn1.innerHTML = '<cite>确定</cite>';
        btn1.onclick = function () {
        	if(okCallback)
        		okCallback(callParam);
            document.body.removeChild(alertBox);
            document.body.removeChild(shadowDiv);
            return true;
        };
        alertBox.appendChild(btn1);
    }
    
    if (mode === 1) {
    	var btn1 = document.createElement('a');
        btn1.id = 'alertMsg_btn1';
        btn1.href = 'javas' + 'cript:void(0)';
        btn1.innerHTML = '<cite>取消</cite>';
        btn1.onclick = function () {
        	if(cancelCallBack)
        		cancelCallBack();
            document.body.removeChild(alertBox);
            document.body.removeChild(shadowDiv);
            return true;
        };
        alertBox.appendChild(btn1);
        
        var btn2 = document.createElement('a');
        btn2.id = 'alertMsg_btn2';
        btn2.href = 'javas' + 'cript:void(0)';
        btn2.innerHTML = '<cite>确定</cite>';
        btn2.onclick = function () {
        	if(okCallback)
        		okCallback(callParam);
            document.body.removeChild(alertBox);
            document.body.removeChild(shadowDiv);
            return false;
        };
        alertBox.appendChild(btn2);
    }
    document.body.appendChild(alertBox);

}

//弹出小框
function showBlock(id){
	$("#"+id).css({"display":"block","z-index":101});
	createBg();
	$("#lock_click_bg").unbind();
	$("#lock_click_bg").bind("click",function(){$("#lock_click_bg").hide();$("#"+id).hide()});
}
//隐藏遮罩层
function createBg(){
	if($("#lock_click_bg").is(".lock_click_bg")){
		$("#lock_click_bg").show();
	}else{
		$("body").append("<div id='lock_click_bg' class='lock_click_bg' style='position:absolute;left: 0px; top: 0px;display:none'></div>");
		$("#lock_click_bg").show();
		var lock = $("#lock_click_bg");
		var height = $(document).height();
		var width = $(document).width();
		lock.css("height", height);
		lock.css("width", width);
		//lock.css("background","url(../img/bg_fix.png)"); 
		lock.css("z-index",100);
	}
}

//书架操作按钮弹出框
$.fn.popover=function(){
	var popoverClick=$(this).children();
	$(popoverClick).click(function(e){
		var showDocument=$(this).find(".popover-panel");
       	$(showDocument).show();
        e.stopPropagation();
        $(this).siblings().find(".popover-panel").hide();
    });
    $(".popover-panel").click(function(e){
	    e.stopPropagation();
	});
	$(document.body).click(function(){
     	$(".popover-panel").hide();
   	});
}
//健康告知列表树
$.fn.checkMenu=function(){
	var checkOne = $(this).find('.checkMenuOne');
	$(checkOne).click(function(){
 		var checkOneSpan=$(this).find('span');
		if($(checkOneSpan).hasClass("check_yes")||$(checkOneSpan).hasClass("x")){
			$(this).next("div").show();
			myScroll.refresh(); 
		}else{
			$(this).next("div").hide();
			myScroll.refresh(); 
		}
	})
}
//产品热卖左右滑动
$.fn.swiperProduct=function(){
	var mySwiper= new Swiper(".featured",{	    
	    slidesPerView:3,
	    loop:true,
	    initialSlide :-1,speed:300,
	    tdFlow: {
	      rotate : 0,
	      stretch :10,
	      depth: 150,
	      shadows : false
	    }
	})
}
// 书架批量删除
$.fn.removeBookshelf=function(){
	$(this).click(function(){
		$(this).hide();
		$(this).removeClass("block");
		$(this).prev("a").hide();
		$(this).prev("a").removeClass("block");
		$(this).prev("a").prev("a").hide();
		$(this).prev("a").prev("a").removeClass("block");
		$(this).next("a").show();
		$(this).next("a").next("a").show();
		$(".check-list").show();
		$(".popover-panel").parent("div").hide();
		// 返回
		$(".icon-return").click(function(){
			var thisReturn=$(this).parent("a");
			$(thisReturn).hide();
			$(thisReturn).removeClass("block");
			$(".check-list").hide();
			$(".check-list input").prop("checked",false);//选择rest
			$(".popover-panel").parent("div").show();
			$(".popover-panel").hide();//操作按钮框rest
			$(thisReturn).next("a").hide();
			$(thisReturn).prev("a").show();
			$(thisReturn).prev("a").prev("a").show();
			$(thisReturn).prev("a").prev("a").prev("a").show();
		});
		$('input').each(function(index,me){
			var obj  = $(me).parent().parent().data("data")
			if(obj.allowDel=="N"&&obj.allowDel){
				$(me).attr("disabled","disabled");
			}
		});
	})
}
/*复选以及全选*/
$.fn.chkAll=function(){
 var findmain = $(this).find('span')
 $(findmain).click(function(){
	 	if($(this).is(".check_no")){
		$(this).addClass('check_yes')
		$(this).removeClass('check_no')
		 }else{
			 $(this).addClass('check_no')
			 $(this).removeClass('check_yes')
		 }
  	})
 $(".chk_all").toggle(
	function(){$(this).parent().find("span").attr("class","check_yes")},
	function(){$(this).parent().find("span").attr("class","check_no")}
	);
}
/*单选*/
$.fn.radioAll=function(){
	var radioChild = $(this).find('span')
 	$(radioChild).click(function(){
		if($(this).hasClass("radio_nocheck")){
			$(this).parent().find("span").attr("class","radio_nocheck")
			$(this).attr("class","radio_checked") 
			if($(this).attr("id")!="otherWenben"){
				$("#wenben").val("");
				$("#wenben").attr("disabled","disabled");
			}else{
				$("#wenben").removeAttr("disabled");
			}
		}  
  	})
}
/*单选是否*/
$.fn.radioJudge=function(){
 	var radioChild = $(this).find('span')
 	$(radioChild).click(function(){
		if($(this).hasClass("radio_no")){
			$(this).parent().find("span").attr("class","radio_no")
		 	$(this).attr("class","radio_yes") 
		}  
  	})
}
/*单选性别*/
$.fn.radioSex=function(){
	if($(this).hasClass("disabled")){
		return false
	}else{
		var radioSexChild = $(this).find('label')
		$(radioSexChild).click(function(){
			if(!($(this).hasClass("active")) ){
				$(this).parent().find("label").removeClass("active");
				$(this).addClass("active");
			}
		})
	}
}
/*单选是否判断折叠-健康告知*/
$.fn.collapseRadio=function(){
 	var collapseRadioChild = $(this).find('span');
 	$(collapseRadioChild).click(function(){
 		var collapseShow=$(this).parent().find('span:first-child');
 		var collapsePanel=$(this).parent().next('div');
	 	if($(collapseShow).hasClass("radio_yes")){
	 		$(collapsePanel).show();
			myScroll.refresh(); 
	 	}else{
	 		$(collapsePanel).hide();
	 		$(collapsePanel).find('.check_blo span').attr("class","check_no");
	 		$(collapsePanel).find('.checkTree div').hide();
			myScroll.refresh(); 
	 	}
  	})
}
// 健康告知全部否
$.fn.radioJudgeAllNo=function(){
	$(this).click(function(){
		$(".radio_judge").find("span:even").attr("class","radio_no");
		$(".radio_judge").find("span:odd").attr("class","radio_yes");
		$(".radio_judge").next("div").hide();
	 	$(".radio_judge").next("div").find('.check_blo span').attr("class","check_no");
	 	$(".radio_judge").next("div").find('.checkTree div').hide();
	 	myScroll.refresh(); 
	})
}
//Swipertab滑块切换
//$.fn.tabSwiper=function(){
//
//	var tabsSwiper = $(this).swiper({
//		calculateHeight : true,
//	    onSlideChangeEnd: function (swiper) {
//	      $(".tabs-line .active").removeClass('active');
//	      $(".tabs-line a").eq(tabsSwiper.activeIndex).addClass('active');
//		},
//		onSlideClick: function(){
//			event.preventDefault()
//		}
//	})
//	$(".tabs-line a").on('touchstart mousedown',function(e){
//		e.preventDefault()
//	    $(".tabs-line .active").removeClass('active')
//	    $(this).addClass('active')
//	    tabsSwiper.swipeTo($(this).index())
//	})
//	$(".tabs-line a").click(function(e){
//		e.preventDefault()
//	})
//}
//Swipertab滑块切换走进安联
$.fn.tabIntoSwiper=function(){
	var tabsSwiper = $(this).swiper({
		calculateHeight : true,
	    onSlideChangeEnd: function (swiper) {
	      $(".into-tabs-line .active").removeClass('active');
	      $(".into-tabs-line a").eq(tabsSwiper.activeIndex).addClass('active');
	      var swiperH=$(".swiper-slide-active").children().height();
	      $(".content-slide").parent("div").height(swiperH);
	      $(".swiper-wrapper").height(swiperH);
	      myScroll4.refresh();
		}
	})
	$(".into-tabs-line a").on('touchstart mousedown',function(e){
		e.preventDefault()
	    $(".into-tabs-line .active").removeClass('active')
	    $(this).addClass('active')
	    tabsSwiper.swipeTo($(this).index())
	})
	$(".into-tabs-line a").click(function(e){
		e.preventDefault()
	})
}
//弹出层调用
function showDiv(id,e){
	$.openPopupLayer({
		  name: id,
		  target: id
	  }); 
	$("#popupLayerScreenLocker").click(function(){
		if("undefined" != typeof timeFlag){
			if(timeFlag){
				if(timeInit){
					clearInterval(timeInit);
				}			
				timeFlag=false;
			}

		}
		$.closePopupLayer(id);
	})
	//弹出层tab左右滑动
	if($("#leftTabBox")){
	 TouchSlide({ slideCell:"#leftTabBox" });
	};
  	//弹出层里下拉框显示$(".open_block select").css({visibility : "visible"});
	if(id == "agn-menu") {
		openAgnMenu();
	}
/*    myScroll.refresh(); 
	myScroll1.refresh();*/
}

/*function openAgnMenu() {
	var menuHtml = "<div class='circle-panel'>";
	menuHtml += "<nav class='circle-bg'>";
	menuHtml += "<a class='circle-pic' onclick='getUserInfo()'><img src='/pad_marketing/html/img/circle-bird.png'></a>";
	menuHtml += "<lable class='circle-text'></lable>";
	menuHtml += "<div class='circle-menu'>";
	menuHtml += "<a href='/pad_marketing/about/aboutUs.action' class='menu-item' id='menu-one'><i class=''>公司介绍</i>";
	menuHtml += "<a href='/pad_marketing/main/type005pkgGetHot.action' class='menu-item' id='menu-two'><i class=''>产品中心</i></a>";
	menuHtml += "<a href='javascript:;' onclick='need()' class='menu-item' id='menu-three'><i class=''>需求分析</i></a>";
	menuHtml += "<a href='/pad_marketing/plan/proposalMange.action' class='menu-item' id='menu-four'><i class=''>建议书</i></a>";
	menuHtml += "<a href='/pad_marketing/ordermanager/index.action' class='menu-item' id='menu-five'><i class=''>在线投保</i></a>";
	menuHtml += "</div><span class='close circle-close' onClick=\"closeDiv('agn-menu')\">X</span><a class='out' href='javascript:;' onclick='logOut()'>退出</a></nav></div>";
	document.getElementById("agn-menu").innerHTML = menuHtml;
}*/

function need(){
	closeDiv('agn-menu');
	goAnalysis('');
}

function SignJS(){
	goSign("a");
}
function a(src){
	var img=document.getElementById("img0");
	src = 'data:image/png;base64,' + src;			
	img.src = src;
}
function b(){
	goSign1("v");
}
function v(src){
	var img=document.getElementById("img0");
	src = 'data:image/png;base64,' + src;			
	img.src = src;
}

function closeDiv(id){
$.closePopupLayer(id);
}
$.fn.aboutHistory=function(){
  var arr= new Array()
  for(var i=0;i<=$(".swiper-film li").length;i++){
    arr[i]=$(".swiper-film li").eq(i-1).html();
  }
  var navCon = document.getElementById("film_con");
  var navSwiper = new Swiper('.swiper-nav',{
      paginationClickable: true, //值为true时，点击分页器的指示点时会发生Swiper。
      centeredSlides: true, //若为false，居左
      slidesPerView: 5,//分几页
      watchActiveIndex: true,//监控活动块的索引。
      loop:true,//循环
      onTouchEnd: function(){
          for (i=1;i<arr.length;i++){
            if(navSwiper.activeLoopIndex+1==i){
                navCon.innerHTML=arr[i];
				$('.swiper-nav .swiper-slide').attr("onClick","")
  				$('.swiper-nav .swiper-slide-active').attr("onClick","showDiv('open"+i+"')")
            }
          }
      	},
      onSlideClick: function(){
      		navSwiper.swipeTo(navSwiper.clickedSlideIndex-5);
      		for (i=1;i<arr.length;i++){
            	if(navSwiper.activeLoopIndex+1==i){
	                navCon.innerHTML=arr[i];
	            }
	        }
    	}
	})
}
//超出滚动 
if($("#wrapper")){
var myScroll;
function loaded() {
	myScroll = new iScroll('wrapper',{ hScrollbar: false, vScrollbar: false});
}
window.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
}

if($("#wrapper1")){
var myScroll1;
function loaded1() {
myScroll1 = new iScroll('wrapper1',{ hScrollbar: false, vScrollbar: false});
}
window.addEventListener('DOMContentLoaded', function () { setTimeout(loaded1, 200); }, false);
}

if (location.hash) {
    window.scrollTo(0, 0);
}

//IScroll初始化
if($("#wrapper2")){
var myScroll2;
function loaded2() {
	myScroll2 = new iScroll('wrapper2',{ hScrollbar: false, vScrollbar: false});
	if (location.hash) {               
	    setTimeout(function () {
	    myScroll2.scrollToElement(location.hash, 0);
	     }, 50);
	}
	//关键代码
	$('.a-z a[href^="#"]').on('click', function (e) {
	    //阻止默认点击事件
	    e.preventDefault();
	    var target = this.hash;
	    $target = $(target);
	    myScroll2.scrollToElement(target,0);
	    return false
	});  
}
window.addEventListener('DOMContentLoaded', function () { setTimeout(loaded2, 200); }, false);
}

if($("#wrapper3")){
var myScroll3;
function loaded3() {
	myScroll3 = new iScroll('wrapper3', {
		snap: true,
		momentum: false,
		hScrollbar: false,
		onScrollEnd: function () {
			document.querySelector('.indicator > li.active').className = '';
			document.querySelector('.indicator > li:nth-child(' + (this.currPageX+1) + ')').className = 'active';
		}
	 });
}
document.addEventListener('DOMContentLoaded', loaded3, false);
}

if($("#wrapper4")){
var myScroll4;
function loaded4() {
	$(".tabSwiperInto").tabIntoSwiper();
	myScroll4 = new iScroll('wrapper4',{vScrollbar: false, vScrollbar: false});
}
window.addEventListener('DOMContentLoaded', function () { setTimeout(loaded4, 200); }, false);
}

if($("#wrapper5")){
var myScroll5;
function loaded5() {
	myScroll5 = new iScroll('wrapper5',{ hScrollbar: false, vScrollbar: false});
}
window.addEventListener('DOMContentLoaded', function () { setTimeout(loaded5, 200); }, false);
}
